{% extends "template_register.html" %}
{% load staticfiles %}
{% block title %}Register{% endblock %} 
{% block content %}
<form method="post" class="form-signin" enctype="multipart/form-data" action="{% url 'register' %}">
		{% csrf_token %}
		
        <h2 class="form-signin-heading" style="text-align:center">注册</h2>
        <div style="display:none;color:red" id="message_show" >
        </div>
        
        <label for="id_username" class="sr-only">userName:</label>
        <input type="text" class="form-control" id="id_username" maxlength="100" name="username"  placeholder="UserName" required autofocus>
        
        <label for="id_email" class="sr-only">Email address</label>
        <input type="email"  class="form-control" id="id_email" name="email" placeholder="Email address" required>
        
        <label for="id_phone" class="sr-only">phone:</label>
        <input type="text" class="form-control" id="id_phone"  maxlength="11" name="phone"  placeholder="Phone number" required>
        
        <label for="id_password" class="sr-only">Password</label>
        <input type="password" class="form-control" id="id_password" name="password" placeholder="Password" required>
        
        <label for="id_repassword" class="sr-only">Repeat Password:</label>
        <input type="password" class="form-control" id="id_repassword"  name="repassword" placeholder="Repeat Password" required>
       
        <input class="btn btn-lg btn-primary btn-block" type="submit" value="注册" onClick="return validate()">
        <input class="btn btn-lg btn-primary btn-block" onClick="login('{{ login_url }}')" value="登录">
        <script type="text/javascript">
        	function login(url){
        		window.location.href=url
        	}
        	function validate(){
        		 $("#message_show").hide();
        		 var input_dict = {};
                 $('input').each(function(){
                     var v = $(this).val();
                     var n = $(this).attr('name');
                     input_dict[n] = v;
                 });
                 var flag;
                 $.ajax({
                     url: '/regist_check/',
                     type: 'POST',
                     data: input_dict,
                     async: false,
                     dataType: 'json',
                     success: function (result) {
                    	 flag = result.flag;
                    	 if(!flag){
                    		 message = result.value;
                    		 $("#message_show").html(message);
                        	 $("#message_show").show();
                         }
                     }
                 })
                 return flag;
        	}
        </script>
</form>
<br>
{% endblock %}
{% block js %} 
<!-- jQuery -->
<script src="{% static 'vendors/jquery/dist/jquery.min.js' %}"></script>
{% endblock %}